package flca.mda.api.util;

import java.lang.reflect.Field;

public class FlexTypeUtils extends WebappTypeUtils 
{
	private NameUtils nu = new NameUtils();
	private TypeUtils tu = new TypeUtils();
	
	@Override
	public String getIdTypeName() 
	{
		String result = tu.getIdTypeName();
		result = nu.getIniFileValue("flex.pkType", result);
		return result;
	}
	
	@Override
	public String getIdTypeName(Class<?> aClass) {
		String result = getIdType(aClass).getSimpleName();
		result = nu.getIniFileValue("flex.pkType", result);
		return result;
	}
	
	@Override
	public String getTypeName(Field aField) 
	{
		String result = null;
		if (tu.isEnum(aField)) {
			result = super.getTypeName(aField);
		} else if (tu.isPrimitive(aField) || tu.isSimpleField(aField)) {
			result = nu.getIniFileValue("flex.datatype", tu.getTypeName(aField));
		} else if (tu.isCollection(aField)) {
			result = tu.getGenericTypeName(aField);
		} else {
			result = tu.getTypeName(aField);
		}
		if (result == null) {
			logger.warn("could not obtain type for field : " + aField.getName());
			result = "???";
		}
		return result;
	}
	
}
